package tcp

import (
	"fmt"
	"log"
	"net"
)

//StartTcpServerWithEpoll 固定长度的解析TCP包
// TODO husd 目前还没做。
func StartTcpServerWithEpoll(handle func([]byte), ip string, port int) {
	ipPort := fmt.Sprintf("%s:%d", ip, port)
	log.Printf("start tcp server ip:port %v \n", ipPort)
	listen, err := net.Listen("tcp", ipPort)
	if err != nil {
		fmt.Println("listen failed, err:", err)
		return
	}
	defer listen.Close()
	log.Printf("start tcp server success")
	for {
		conn, err := listen.Accept() // 建立连接
		if err != nil {
			fmt.Println("accept failed, err:", err)
			continue
		}
		go handleConn(conn, handle)
	}
}
